package com.spica.platform.feign.service;

import com.spica.platform.feign.client.GenericFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.Future;

/**
 * 异步通用服务类
 */
@Component
public class AsyncGenericService {
    @Lazy
    @Resource
    GenericFeignClient genericFeignClient;

    @Async
    public <T> Future<String> get(String serviceId, String url, T params) {
        String result = genericFeignClient.get(serviceId, url, params);
        return new AsyncResult<String>(result);
    }

    @Async
    public <T> Future<String> post(String serviceId, String url, T params) {
        String result = genericFeignClient.post(serviceId, url, params);
        return new AsyncResult<String>(result);
    }
}
